package com.application.fabric.fabriccontrol.operate.serverfabric;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import org.springframework.stereotype.Repository;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

@Repository
public class PDFservice {
//    生成pdf文件进入hdfs
    public void writePDF(){
        try {
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream("src/main/java/com/application/fabric/fabriccontrol/existevidence/capool/output.pdf"));
            document.open();
            Paragraph p1 = new Paragraph("Fabric  Voucher");
            /*居中对齐*/
            p1.setAlignment(Element.ALIGN_CENTER);
            setStyle(p1,50,30,10,10,10,0);
            document.add(p1);


            Paragraph p12 = new Paragraph("--------------------------------------------------");
            /*居中对齐*/
            p12.setAlignment(Element.ALIGN_CENTER);
            setStyle(p12,50,30,10,10,10,0);
            document.add(p12);

            Paragraph p2 = new Paragraph("certificate:"+"dfrs;gokop[ergko");
            setStyle(p2,30,30,10,10,10,100);
            document.add(p2);

            Paragraph p3 = new Paragraph("hash ID:"+"liefhoiejfo");
            setStyle(p3,30,30,10,10,10,100);
            document.add(p3);


            Paragraph p4 = new Paragraph("block address:"+"liefhoiejfo");

            setStyle(p4,30,30,10,10,10,100);
            document.add(p4);

            Paragraph p5 = new Paragraph("file name:"+"liefhoiejfo");
            setStyle(p5,30,30,10,10,10,100);
            document.add(p5);

            Paragraph p6 = new Paragraph("time:"+"liefhoiejfo");
            setStyle(p6,30,30,10,10,10,100);
            document.add(p6);


//            Font font = FontFactory.getFont("宋体", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//            Paragraph paragraph = new Paragraph("你好，世界！", font);
//            setStyle(paragraph,30,30,10,10,10);
//            document.add(paragraph);
            Paragraph p7 = new Paragraph("mechanism:"+"liefhoiejfo");
            setStyle(p7,30,30,10,10,10,100);
            document.add(p7);


            Paragraph p13 = new Paragraph("--------------------------------------------------");
            /*居中对齐*/
            p13.setAlignment(Element.ALIGN_CENTER);
            setStyle(p13,50,30,10,10,10,0);
            document.add(p12);


            Paragraph p8 = new Paragraph("explain:");
            setStyle(p8,30,40,10,10,10,150);
            document.add(p8);


            Paragraph p9 = new Paragraph(" This file is encrypted by sm3");
            setStyle(p9,30,20,10,10,10,160);
            document.add(p9);



            Paragraph p11 = new Paragraph("Data cannot be tampered with through fabric storage");
            setStyle(p11,30,20,10,10,10,160);
            document.add(p11);



            document.close();
        } catch (DocumentException | FileNotFoundException e) {
            e.printStackTrace();
        }
    }

private  Paragraph setStyle(Paragraph p, int setPaddingTop, int setSize, int setColor1, int setColor2, int setColor3, int left){
    p.setPaddingTop(setPaddingTop);
//      Font font = new Font();
    Font font = FontFactory.getFont(FontFactory.HELVETICA, 4f);
    font.setSize(setSize);
    font.setColor(setColor1,setColor2,setColor3);
    p.setFont(font);
    p.setIndentationLeft(left);
    return p;
}
}
